<template>
<div id="content">
  <router-view/>
</div>
</template>

<script lang="ts">
import { Vue, Component } from 'vue-property-decorator';
import axios from '@/utils/request';
declare const wx: any;

@Component
export default class index extends Vue {

  loadSrc(e: any) {
    console.log(e);
    let win = e.contentWindow || e.contentDocument;
    console.log(win, 'win');
  }

  mounted() {
    let ua = navigator.userAgent.toLowerCase();
    let isWeixin = ua.indexOf('micromessenger') > -1;
    if(isWeixin) {
      this.$toast.loading({ mask: true, message: '加载中...', duration: 0 });
      axios.get('/api/login/wxJsSdkConfig', {
        url: window.location.href.split('#')[0]
      }).then((res: any) => {
        let config: any = res || {};
        this.$store.commit('setState', { config });
        wx.config({ ...config, debug: false, jsApiList: [ 'scanQRCode', 'chooseImage', 'uploadImage', 'getLocation', 'openLocation' ] });
        wx.ready((res: any) => {
          this.$toast.clear();
          this.$store.commit('setState', { wxSwitch: 1 }); 
        });
        wx.error((res: any) => {
          this.$toast.clear();
          this.$store.commit('setState', { wxSwitch: 2 });
        });
      });
    } else {
      this.$store.commit('setState', { wxSwitch: 2 });
    }
  }
  
};
</script>

<style lang="scss">
* { margin: 0; padding: 0; }
img { display: block; }
html, body, #content { width: 100%; height: 100%; }
.btn_style {
  width: 1.2rem; 
  height: 0.6rem; 
  line-height: 0.6rem; 
  box-sizing: border-box; 
  background: #ff976a; 
  display: inline-block; 
  border-radius: 0.1rem; 
  text-align: center; 
  color: #fff;
}
</style>

